package Chapter2.Comparing.c8;

import java.io.*;

public class FileInputDemo {
    public static void main(String[] args) {
        File sourc = new File("E:\\Test\\test1.txt");
        File des = new File("E:\\Test\\test2.txt");

        try {
            FileInputStream fis = new FileInputStream("E:\\Test\\test1.txt");
            int a;
            while ((a = fis.read())!=-1) {
                System.out.print((char) a);
            }
            //System.out.print(a);
            copyFileFileStreams(sourc,des );
        }
        catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
        }
        catch (IOException e){
            e.printStackTrace();
        }

        //copyFileFileStreams(sourc,des );
    }

    public static void copyFileFileStreams(File source, File dest) throws IOException {
        InputStream input = null;
        OutputStream output = null;

        try{
            input = new FileInputStream(source);
            output = new FileOutputStream(dest);
            byte [] buf = new byte[1024];
            int bytesRead;
            while ((bytesRead = input.read())!=-1) {
                output.write(buf,0,bytesRead);
            }
        }
        finally {
            input.close();
            output.close();
        }
    }

}
